package com.semp.gu.ui.util;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;

public class FramePostioner {

	public static void center(JFrame frame) {
		//Get the screen size 
		Toolkit toolkit = Toolkit.getDefaultToolkit(); 
		Dimension screenSize = toolkit.getScreenSize(); 

		//Calculate the frame location 
		int x = (screenSize.width - frame.getWidth()) / 2; 
		int y = (screenSize.height - frame.getHeight()) / 2; 

		//Set the new frame location 
		frame.setLocation(x, y);	
	}
	
	public static void center(Component component, Component parentComponent) {
		//Get the parent component size 
		Dimension parentSize = parentComponent.getSize();

		//Calculate the component location 
		int x = (parentSize.width - component.getWidth()) / 2; 
		int y = (parentSize.height - component.getHeight()) / 2; 

		//Set the new component location 
		component.setLocation(x, y);	
	}
	
}
